// components/amount/index.js
var service = require('../../service/port')

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    radio: "",
    nodata: false,
    storeList: [
    ],
    store: {}
  },

  attached() {
    service.getStore({
      "queryRequest": {
        pageNum: 1,
        pageSize: 2000
      }
    }, res => {
      console.log(res);
      if(res.code=="00000"){
        if(res.data.rows.length==0){
          this.setData({
            nodata:true
          })
        }else{
          this.setData({
            storeList:res.data.rows,
            nodata:false
          })
        }
      }
      
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      //console.log(event.detail);

      this.setData({
        radio: event.detail,
      });
      this.data.storeList.forEach(item => {
        if (item.storeId == event.detail) {
          this.setData({
            store: item
          })
        }
      })
      
      // wx.setStorageSync('currentAddress', address)
      // wx.redirectTo({
      //   url: '/pages/order/confirmorder/index?address=' + JSON.stringify(address)
      // })

    },
    onClick(event) {
      const { name } = event.currentTarget.dataset;
      this.setData({
        radio: name,
      });
      this.data.storeList.forEach(item => {
        if (item.storeId == name) {
          this.setData({
            store: item
          })
        }
      })
    },
    confirm(){
      if(!this.data.store.storeId){
        wx.showToast({ title: '请选择门店！', icon: 'none' });
        return
      }
      this.triggerEvent('myevent', this.data.store)
    }
  }
})